/*
 *               ____
 *              /\   \
 *             ___\   \___
 *            /\          \
 *            \ \___    ___\
 *        ____ \/__/\   \__/
 *       /\   \    \ \___\    klof  |  innovative web technology
 *      ___\   \___ \/___/
 *     /\          \          klib3/script.js
 *     \ \___    ___\         Load external scripts after the page is loaded
 *      \/__/\   \__/
 *          \ \___\           Copyright 2003-2006, klof
 *           \/___/           http://www.klof.net/k.lib3/
 *
 *                            requirements: /
 */


/* Create the master klib3 object if she doesn't exist */
if ( typeof klib3 != "object" )
	klib3 = new ( function(){ this._child = 0 } )();



klib3.flash = function()
{
	this._version  = "1.0.0";
	this._property = {
		type:"application/x-shockwave-flash",
		width:"100%",
		height:"100%",
		menu:"false",
		quality:"high"
	};
};
klib3.flash.set = function( sProperty, mValue )
{
	this._property[ sProperty ] = mValue;
};
klib3.flash.prototype.mergeParam = function( oParam )
{
	var oProperty = this._property;

	if ( typeof oParam == "object" )
		for ( var p in oParam )
			oProperty[ p ] = oParam[ p ];
	return oProperty;
};
klib3.flash.prototype.createObjectHTML = function( oParam )
{
	var oProperty = this.mergeParam( oParam );
	var sReturn   = "<object data=\"" + oProperty.movie + 
					"\" type=\"" + oProperty.type + 
					"\" width=\"" + oProperty.width + 
					"\" height=\"" + oProperty.height + 
					"\">";
	

	for ( var p in oProperty )
		if ( typeof oProperty[ p ] != "undefined" )
		{
			switch( p.toLowerCase() )
			{
				case "width":
				case "height":
				case "type":
					break;
				default:
					sReturn += "<param name=\"" + p + "\" value=\"" + oProperty[ p ] + "\" />";
					break;
			}
		}

	sReturn += "</object>";
	return sReturn;
};
klib3.flash.prototype.createDOMObject = function( oParam )
{
	if ( typeof document.createElement == "undefined" )
		return false;

	var oObject   = document.createElement( "object" );
	var oProperty = this.mergeParam( oParam );

	for ( var p in oProperty )
		if ( typeof oProperty[ p ] != "undefined" )
		{
			switch( p.toLowerCase() )
			{
				case "width":
				case "height":
				case "type":
					oObject[ p ] = oProperty[ p ]; 
					break;
				case "movie":
					if ( typeof oObject.outerHTML == "undefined" && navigator.appName.toLowerCase().indexOf( "mac" ) < 0 )
						oObject.data = oProperty[ p ]; 
					// no break, since we need to set the movie in both the object (data) as in a param (name=movie)
				default:
					var oParamNode   = document.createElement( "param" );
					oParamNode.name  = p;
					oParamNode.value = oProperty[ p ];
					oObject.appendChild( oParamNode );
					break;
			}
		}

	if ( typeof oObject.outerHTML != "undefined" && navigator.appName.toLowerCase().indexOf( "mac" ) < 0 )
	{
		oObject.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" );
		oObject.setAttribute( "codebase", "http://download.macromedia.com/pub/shockwave/cabs/flash/" );
	}

	if ( typeof oObject != "undefined" && typeof oObject.nodeType == "number" && oObject.nodeType == 1 )
		return oObject;
	return false;
};
klib3.flash.prototype.autofix = function()
{
	if ( typeof navigator.product == "undefined" )
	{
		if ( !document.getElementsByTagName )
			return false;
		var aObject = document.getElementsByTagName( "object" );
		if ( aObject.length > 0 && aObject[ 0 ].outerHTML ) // We know very few browsers know about outerHTML (which is a good thing), IE is amongst those few
			for ( var i = 0; i < aObject.length; ++i )
				if ( aObject[ i ].outerHTML )
				{
					if ( typeof aObject[ i ].data != "undefined" )
						aObject[ i ].removeAttribute( "data" );
					aObject[ i ].outerHTML = aObject[ i ].outerHTML;
					aObject[ i ].style.display = "block";
				}
	}
	return true;
};
klib3.flash.prototype.attach = function( mElement, oParam )
{
	if ( typeof mElement == "string" && document.getElementById )
		mElement = document.getElementById( mElement );

	if ( typeof mElement == "object" && typeof mElement.appendChild != "undefined" )
	{
		var oObject = this.createDOMObject( oParam );
		if ( typeof oObject != "undefined" && typeof oObject.nodeType == "number" && oObject.nodeType == 1 )
			return mElement.appendChild( oObject );
	}
	return false;
};
klib3.flash.prototype.write = function( oParam )
{
	document.write( this.createObjectHTML( oParam ) );
};


// construct the klib3.flash Object onto itself so we have access to it's members
klib3.flash = new klib3.flash;
